#
# OMNeT++/OMNEST Makefile for $(LIB_PREFIX)INET
#
# This file was generated with the command:
#  opp_makemake --make-so -f --deep -o INET -O out -pINET -I.
#

# Name of target to be created (-o option)
TARGET = $(LIB_PREFIX)INET$(D)$(SHARED_LIB_SUFFIX)
TARGET_DIR = .

# C++ include paths (with -I)
INCLUDE_PATH = -I.

# Additional object and library files to link with
EXTRA_OBJS =

# Additional libraries (-L, -l options)
LIBS =

# Output directory
PROJECT_OUTPUT_DIR = ../out
PROJECTRELATIVE_PATH = src
O = $(PROJECT_OUTPUT_DIR)/$(CONFIGNAME)/$(PROJECTRELATIVE_PATH)

# Object files for local .cc, .msg and .sm files
OBJS = \
    $O/inet/applications/base/ApplicationBase.o \
    $O/inet/applications/tcpapp/TcpAppBase.o \
    $O/inet/applications/tcpapp/TcpBasicClientApp.o \
    $O/inet/applications/tcpapp/TcpClientSocketIo.o \
    $O/inet/applications/tcpapp/TcpServerListener.o \
    $O/inet/applications/tcpapp/TcpServerSocketIo.o \
    $O/inet/applications/udpapp/UdpBasicApp.o \
    $O/inet/applications/udpapp/UdpEchoApp.o \
    $O/inet/applications/udpapp/UdpSink.o \
    $O/inet/applications/udpapp/UdpSocketIo.o \
    $O/inet/common/Compat.o \
    $O/inet/common/IInterfaceRegistrationListener.o \
    $O/inet/common/INETUtils.o \
    $O/inet/common/InitStages.o \
    $O/inet/common/int128.o \
    $O/inet/common/IProtocolRegistrationListener.o \
    $O/inet/common/LayeredProtocolBase.o \
    $O/inet/common/MatchableField.o \
    $O/inet/common/MatchableObject.o \
    $O/inet/common/MemoryInputStream.o \
    $O/inet/common/MemoryOutputStream.o \
    $O/inet/common/MessageDispatcher.o \
    $O/inet/common/ModuleAccess.o \
    $O/inet/common/NedFunctions.o \
    $O/inet/common/PatternMatcher.o \
    $O/inet/common/Protocol.o \
    $O/inet/common/ProtocolGroup.o \
    $O/inet/common/ProtocolTools.o \
    $O/inet/common/ResultFilters.o \
    $O/inet/common/ResultRecorders.o \
    $O/inet/common/Simsignals.o \
    $O/inet/common/StringFormat.o \
    $O/inet/common/TlvOptions.o \
    $O/inet/common/Topology.o \
    $O/inet/common/XMLUtils.o \
    $O/inet/common/checksum/EthernetCRC.o \
    $O/inet/common/checksum/TcpIpChecksum.o \
    $O/inet/common/lifecycle/InterfaceOperations.o \
    $O/inet/common/lifecycle/LifecycleController.o \
    $O/inet/common/lifecycle/ModuleOperations.o \
    $O/inet/common/lifecycle/NodeStatus.o \
    $O/inet/common/lifecycle/OperationalBase.o \
    $O/inet/common/packet/ChunkBuffer.o \
    $O/inet/common/packet/ChunkQueue.o \
    $O/inet/common/packet/Message.o \
    $O/inet/common/packet/Packet.o \
    $O/inet/common/packet/PacketFilter.o \
    $O/inet/common/packet/ReassemblyBuffer.o \
    $O/inet/common/packet/ReorderBuffer.o \
    $O/inet/common/packet/chunk/BitCountChunk.o \
    $O/inet/common/packet/chunk/BitsChunk.o \
    $O/inet/common/packet/chunk/ByteCountChunk.o \
    $O/inet/common/packet/chunk/BytesChunk.o \
    $O/inet/common/packet/chunk/Chunk.o \
    $O/inet/common/packet/chunk/cPacketChunk.o \
    $O/inet/common/packet/chunk/EmptyChunk.o \
    $O/inet/common/packet/chunk/FieldsChunk.o \
    $O/inet/common/packet/chunk/SequenceChunk.o \
    $O/inet/common/packet/chunk/SliceChunk.o \
    $O/inet/common/packet/dissector/PacketDissector.o \
    $O/inet/common/packet/dissector/ProtocolDissector.o \
    $O/inet/common/packet/dissector/ProtocolDissectorRegistry.o \
    $O/inet/common/packet/serializer/BytesChunkSerializer.o \
    $O/inet/common/packet/serializer/ChunkSerializer.o \
    $O/inet/common/packet/serializer/ChunkSerializerRegistry.o \
    $O/inet/common/packet/serializer/EmptyChunkSerializer.o \
    $O/inet/common/packet/serializer/FieldsChunkSerializer.o \
    $O/inet/common/packet/serializer/SequenceChunkSerializer.o \
    $O/inet/common/packet/tag/RegionTagSet.o \
    $O/inet/common/packet/tag/TagSet.o \
    $O/inet/common/socket/SocketMap.o \
    $O/inet/linklayer/base/MacProtocolBase.o \
    $O/inet/linklayer/common/FcsMode.o \
    $O/inet/linklayer/common/MacAddress.o \
    $O/inet/linklayer/common/MacAddressType.o \
    $O/inet/linklayer/configurator/Ieee8021dInterfaceData.o \
    $O/inet/linklayer/ethernet/EtherEncap.o \
    $O/inet/linklayer/ethernet/EtherMac.o \
    $O/inet/linklayer/ethernet/EtherMacBase.o \
    $O/inet/linklayer/ethernet/EtherMacFullDuplex.o \
    $O/inet/linklayer/ethernet/EthernetHeaderSerializer.o \
    $O/inet/linklayer/ethernet/EthernetSocket.o \
    $O/inet/linklayer/ethernet/switch/MacAddressTable.o \
    $O/inet/linklayer/ieee8022/Ieee8022Llc.o \
    $O/inet/linklayer/ieee8022/Ieee8022LlcSocket.o \
    $O/inet/networklayer/arp/ipv4/Arp.o \
    $O/inet/networklayer/arp/ipv4/ArpPacket.o \
    $O/inet/networklayer/arp/ipv4/GlobalArp.o \
    $O/inet/networklayer/common/EchoProtocol.o \
    $O/inet/networklayer/common/InterfaceEntry.o \
    $O/inet/networklayer/common/InterfaceMatcher.o \
    $O/inet/networklayer/common/InterfaceTable.o \
    $O/inet/networklayer/common/L3Address.o \
    $O/inet/networklayer/common/L3AddressResolver.o \
    $O/inet/networklayer/common/L3Tools.o \
    $O/inet/networklayer/common/ModuleIdAddress.o \
    $O/inet/networklayer/common/ModuleIdAddressType.o \
    $O/inet/networklayer/common/ModulePathAddress.o \
    $O/inet/networklayer/common/ModulePathAddressType.o \
    $O/inet/networklayer/configurator/base/NetworkConfiguratorBase.o \
    $O/inet/networklayer/configurator/ipv4/Ipv4NetworkConfigurator.o \
    $O/inet/networklayer/configurator/ipv4/Ipv4NetworkConfiguratorPFC.o \
    $O/inet/networklayer/configurator/ipv4/Ipv4NodeConfigurator.o \
    $O/inet/networklayer/contract/IArp.o \
    $O/inet/networklayer/contract/IRoute.o \
    $O/inet/networklayer/contract/L3Socket.o \
    $O/inet/networklayer/contract/NetworkHeaderBase.o \
    $O/inet/networklayer/contract/clns/ClnsAddress.o \
    $O/inet/networklayer/contract/clns/ClnsAddressType.o \
    $O/inet/networklayer/contract/ipv4/Ipv4Address.o \
    $O/inet/networklayer/contract/ipv4/Ipv4AddressType.o \
    $O/inet/networklayer/contract/ipv4/Ipv4Socket.o \
    $O/inet/networklayer/ipv4/Icmp.o \
    $O/inet/networklayer/ipv4/Ipv4.o \
    $O/inet/networklayer/ipv4/Ipv4FragBuf.o \
    $O/inet/networklayer/ipv4/Ipv4Header.o \
    $O/inet/networklayer/ipv4/Ipv4InterfaceData.o \
    $O/inet/networklayer/ipv4/Ipv4NatTable.o \
    $O/inet/networklayer/ipv4/Ipv4NetworkLayer.o \
    $O/inet/networklayer/ipv4/Ipv4Route.o \
    $O/inet/networklayer/ipv4/Ipv4RoutingTable.o \
    $O/inet/networklayer/ipv4/RoutingTableParser.o \
    $O/inet/networklayer/nexthop/NextHopForwarding.o \
    $O/inet/networklayer/nexthop/NextHopInterfaceData.o \
    $O/inet/networklayer/nexthop/NextHopRoute.o \
    $O/inet/networklayer/nexthop/NextHopRoutingTable.o \
    $O/inet/node/inet/Mmu.o \
    $O/inet/node/inet/MmuManager.o \
    $O/inet/node/inet/Router.o \
    $O/inet/queueing/base/PacketProcessorBase.o \
    $O/inet/queueing/base/PacketQueueBase.o \
    $O/inet/queueing/base/PacketQueueingElementBase.o \
    $O/inet/queueing/compat/cpacketqueue.o \
    $O/inet/queueing/compat/cqueue.o \
    $O/inet/queueing/function/PacketComparatorFunction.o \
    $O/inet/queueing/function/PacketDropperFunction.o \
    $O/inet/queueing/queue/CompoundPacketQueue.o \
    $O/inet/queueing/queue/PacketQueue.o \
    $O/inet/transportlayer/base/TransportProtocolBase.o \
    $O/inet/transportlayer/common/CrcMode.o \
    $O/inet/transportlayer/common/L4Tools.o \
    $O/inet/transportlayer/common/TransportPseudoHeaderSerializer.o \
    $O/inet/transportlayer/contract/tcp/TcpSocket.o \
    $O/inet/transportlayer/contract/udp/UdpSocket.o \
    $O/inet/transportlayer/tcp/Tcp.o \
    $O/inet/transportlayer/tcp/TcpConnectionBase.o \
    $O/inet/transportlayer/tcp/TcpConnectionEventProc.o \
    $O/inet/transportlayer/tcp/TcpConnectionRcvSegment.o \
    $O/inet/transportlayer/tcp/TcpConnectionSackUtil.o \
    $O/inet/transportlayer/tcp/TcpConnectionUtil.o \
    $O/inet/transportlayer/tcp/TcpReceiveQueue.o \
    $O/inet/transportlayer/tcp/TcpSackRexmitQueue.o \
    $O/inet/transportlayer/tcp/TcpSendQueue.o \
    $O/inet/transportlayer/tcp/flavours/DumbTcp.o \
    $O/inet/transportlayer/tcp/flavours/TcpBaseAlg.o \
    $O/inet/transportlayer/tcp/flavours/TcpNewReno.o \
    $O/inet/transportlayer/tcp/flavours/TcpNoCongestionControl.o \
    $O/inet/transportlayer/tcp/flavours/TcpReno.o \
    $O/inet/transportlayer/tcp/flavours/TcpSegmentTransmitInfoList.o \
    $O/inet/transportlayer/tcp/flavours/TcpTahoe.o \
    $O/inet/transportlayer/tcp/flavours/TcpTahoeRenoFamily.o \
    $O/inet/transportlayer/tcp/flavours/TcpVegas.o \
    $O/inet/transportlayer/tcp/flavours/TcpWestwood.o \
    $O/inet/transportlayer/tcp_common/TcpCrcInsertionHook.o \
    $O/inet/transportlayer/tcp_common/TcpHeader.o \
    $O/inet/transportlayer/udp/Udp.o \
    $O/inet/transportlayer/udp/UdpHeader.o \
    $O/inet/transportlayer/udp/UdpHeaderSerializer.o \
    $O/inet/applications/base/ApplicationPacket_m.o \
    $O/inet/applications/common/SocketTag_m.o \
    $O/inet/applications/tcpapp/GenericAppMsg_m.o \
    $O/inet/common/INETDefs_m.o \
    $O/inet/common/Protocol_m.o \
    $O/inet/common/ProtocolTag_m.o \
    $O/inet/common/Simsignals_m.o \
    $O/inet/common/TagBase_m.o \
    $O/inet/common/TimeTag_m.o \
    $O/inet/common/TlvOptions_m.o \
    $O/inet/common/Units_m.o \
    $O/inet/common/packet/ChunkBuffer_m.o \
    $O/inet/common/packet/ChunkQueue_m.o \
    $O/inet/common/packet/Message_m.o \
    $O/inet/common/packet/Packet_m.o \
    $O/inet/common/packet/chunk/Chunk_m.o \
    $O/inet/custom/controlAdapter_m_m.o \
    $O/inet/linklayer/common/EtherType_m.o \
    $O/inet/linklayer/common/FcsMode_m.o \
    $O/inet/linklayer/common/Ieee802Ctrl_m.o \
    $O/inet/linklayer/common/Ieee802SapTag_m.o \
    $O/inet/linklayer/common/InterfaceTag_m.o \
    $O/inet/linklayer/common/MacAddress_m.o \
    $O/inet/linklayer/common/MacAddressTag_m.o \
    $O/inet/linklayer/common/VlanTag_m.o \
    $O/inet/linklayer/ethernet/EtherFrame_m.o \
    $O/inet/linklayer/ethernet/EthernetCommand_m.o \
    $O/inet/linklayer/ethernet/EtherPhyFrame_m.o \
    $O/inet/linklayer/ieee8021q/Ieee8021qHeader_m.o \
    $O/inet/linklayer/ieee8022/Ieee8022LlcHeader_m.o \
    $O/inet/linklayer/ieee8022/Ieee8022LlcSocketCommand_m.o \
    $O/inet/networklayer/arp/ipv4/ArpPacket_m.o \
    $O/inet/networklayer/common/DscpTag_m.o \
    $O/inet/networklayer/common/EchoPacket_m.o \
    $O/inet/networklayer/common/EcnTag_m.o \
    $O/inet/networklayer/common/FragmentationTag_m.o \
    $O/inet/networklayer/common/HopLimitTag_m.o \
    $O/inet/networklayer/common/InterfaceEntry_m.o \
    $O/inet/networklayer/common/IpProtocolId_m.o \
    $O/inet/networklayer/common/L3Address_m.o \
    $O/inet/networklayer/common/L3AddressTag_m.o \
    $O/inet/networklayer/common/MulticastTag_m.o \
    $O/inet/networklayer/common/NextHopAddressTag_m.o \
    $O/inet/networklayer/common/TosTag_m.o \
    $O/inet/networklayer/contract/L3SocketCommand_m.o \
    $O/inet/networklayer/contract/NetworkHeaderBase_m.o \
    $O/inet/networklayer/contract/clns/ClnsAddress_m.o \
    $O/inet/networklayer/contract/ipv4/Ipv4Address_m.o \
    $O/inet/networklayer/contract/ipv4/Ipv4SocketCommand_m.o \
    $O/inet/networklayer/ipv4/IcmpHeader_m.o \
    $O/inet/networklayer/ipv4/Ipv4Header_m.o \
    $O/inet/networklayer/ipv4/Ipv4NatEntry_m.o \
    $O/inet/networklayer/ipv4/Ipv4OptionsTag_m.o \
    $O/inet/networklayer/ipv4/Ipv4Route_m.o \
    $O/inet/networklayer/nexthop/NextHopForwardingHeader_m.o \
    $O/inet/node/inet/ACLSingleEntry_m.o \
    $O/inet/node/inet/PfcInfoTag_m.o \
    $O/inet/transportlayer/common/CrcMode_m.o \
    $O/inet/transportlayer/common/L4PortTag_m.o \
    $O/inet/transportlayer/common/TransportPseudoHeader_m.o \
    $O/inet/transportlayer/contract/TransportHeaderBase_m.o \
    $O/inet/transportlayer/contract/tcp/TcpCommand_m.o \
    $O/inet/transportlayer/contract/udp/UdpControlInfo_m.o \
    $O/inet/transportlayer/tcp/TcpConnection_m.o \
    $O/inet/transportlayer/tcp_common/TcpHeader_m.o \
    $O/inet/transportlayer/udp/UdpHeader_m.o

# Message files
MSGFILES = \
    inet/applications/base/ApplicationPacket.msg \
    inet/applications/common/SocketTag.msg \
    inet/applications/tcpapp/GenericAppMsg.msg \
    inet/common/INETDefs.msg \
    inet/common/Protocol.msg \
    inet/common/ProtocolTag.msg \
    inet/common/Simsignals.msg \
    inet/common/TagBase.msg \
    inet/common/TimeTag.msg \
    inet/common/TlvOptions.msg \
    inet/common/Units.msg \
    inet/common/packet/ChunkBuffer.msg \
    inet/common/packet/ChunkQueue.msg \
    inet/common/packet/Message.msg \
    inet/common/packet/Packet.msg \
    inet/common/packet/chunk/Chunk.msg \
    inet/custom/controlAdapter_m.msg \
    inet/linklayer/common/EtherType.msg \
    inet/linklayer/common/FcsMode.msg \
    inet/linklayer/common/Ieee802Ctrl.msg \
    inet/linklayer/common/Ieee802SapTag.msg \
    inet/linklayer/common/InterfaceTag.msg \
    inet/linklayer/common/MacAddress.msg \
    inet/linklayer/common/MacAddressTag.msg \
    inet/linklayer/common/VlanTag.msg \
    inet/linklayer/ethernet/EtherFrame.msg \
    inet/linklayer/ethernet/EthernetCommand.msg \
    inet/linklayer/ethernet/EtherPhyFrame.msg \
    inet/linklayer/ieee8021q/Ieee8021qHeader.msg \
    inet/linklayer/ieee8022/Ieee8022LlcHeader.msg \
    inet/linklayer/ieee8022/Ieee8022LlcSocketCommand.msg \
    inet/networklayer/arp/ipv4/ArpPacket.msg \
    inet/networklayer/common/DscpTag.msg \
    inet/networklayer/common/EchoPacket.msg \
    inet/networklayer/common/EcnTag.msg \
    inet/networklayer/common/FragmentationTag.msg \
    inet/networklayer/common/HopLimitTag.msg \
    inet/networklayer/common/InterfaceEntry.msg \
    inet/networklayer/common/IpProtocolId.msg \
    inet/networklayer/common/L3Address.msg \
    inet/networklayer/common/L3AddressTag.msg \
    inet/networklayer/common/MulticastTag.msg \
    inet/networklayer/common/NextHopAddressTag.msg \
    inet/networklayer/common/TosTag.msg \
    inet/networklayer/contract/L3SocketCommand.msg \
    inet/networklayer/contract/NetworkHeaderBase.msg \
    inet/networklayer/contract/clns/ClnsAddress.msg \
    inet/networklayer/contract/ipv4/Ipv4Address.msg \
    inet/networklayer/contract/ipv4/Ipv4SocketCommand.msg \
    inet/networklayer/ipv4/IcmpHeader.msg \
    inet/networklayer/ipv4/Ipv4Header.msg \
    inet/networklayer/ipv4/Ipv4NatEntry.msg \
    inet/networklayer/ipv4/Ipv4OptionsTag.msg \
    inet/networklayer/ipv4/Ipv4Route.msg \
    inet/networklayer/nexthop/NextHopForwardingHeader.msg \
    inet/node/inet/ACLSingleEntry.msg \
    inet/node/inet/PfcInfoTag.msg \
    inet/transportlayer/common/CrcMode.msg \
    inet/transportlayer/common/L4PortTag.msg \
    inet/transportlayer/common/TransportPseudoHeader.msg \
    inet/transportlayer/contract/TransportHeaderBase.msg \
    inet/transportlayer/contract/tcp/TcpCommand.msg \
    inet/transportlayer/contract/udp/UdpControlInfo.msg \
    inet/transportlayer/tcp/TcpConnection.msg \
    inet/transportlayer/tcp_common/TcpHeader.msg \
    inet/transportlayer/udp/UdpHeader.msg

# SM files
SMFILES =

#------------------------------------------------------------------------------

# Pull in OMNeT++ configuration (Makefile.inc)

ifneq ("$(OMNETPP_CONFIGFILE)","")
CONFIGFILE = $(OMNETPP_CONFIGFILE)
else
ifneq ("$(OMNETPP_ROOT)","")
CONFIGFILE = $(OMNETPP_ROOT)/Makefile.inc
else
CONFIGFILE = $(shell opp_configfilepath)
endif
endif

ifeq ("$(wildcard $(CONFIGFILE))","")
$(error Config file '$(CONFIGFILE)' does not exist -- add the OMNeT++ bin directory to the path so that opp_configfilepath can be found, or set the OMNETPP_CONFIGFILE variable to point to Makefile.inc)
endif

include $(CONFIGFILE)

# Simulation kernel and user interface libraries
OMNETPP_LIBS = -loppenvir$D $(KERNEL_LIBS) $(SYS_LIBS)

COPTS = $(CFLAGS) $(IMPORT_DEFINES) -DINET_EXPORT $(INCLUDE_PATH) -I$(OMNETPP_INCL_DIR)
MSGCOPTS = $(INCLUDE_PATH) -PINET_API
SMCOPTS =

# we want to recompile everything if COPTS changes,
# so we store COPTS into $COPTS_FILE and have object
# files depend on it (except when "make depend" was called)
COPTS_FILE = $O/.last-copts
ifneq ("$(COPTS)","$(shell cat $(COPTS_FILE) 2>/dev/null || echo '')")
$(shell $(MKPATH) "$O" && echo "$(COPTS)" >$(COPTS_FILE))
endif

#------------------------------------------------------------------------------
# User-supplied makefile fragment(s)
# >>>
# inserted from file 'makefrag':
.DEFAULT_GOAL := all-pch

#
# Use the new message compiler introduced in OMNeT++ 5.3
#
MSGC:=$(MSGC) --msg6

FEATURETOOL := opp_featuretool

#
# compiler warning for c-style cast
#
#CFLAGS += -Wold-style-cast

ifeq ($(PLATFORM),win32.x86_64)
  #
  # on windows we have to link with the ws2_32 (winsock2) library as it is no longer added
  # to the omnetpp system libraries by default (as of OMNeT++ 5.1)
  #
  LDFLAGS += -lws2_32
  DEFINES += -DINET_EXPORT
  ENABLE_AUTO_IMPORT=-Wl,--enable-auto-import
  LDFLAGS := $(filter-out $(ENABLE_AUTO_IMPORT), $(LDFLAGS))

  # FIX for clang not exporting typinfo and other thunks on Windows
  ifeq ($(CC),clang)
    DEFFILE = $O/typeinfo.def
    LDFLAGS += $(DEFFILE)

$(DEFFILE): $(OBJS)  $(wildcard $(EXTRA_OBJS)) Makefile $(CONFIGFILE)
	@echo Creating .DEF file for $(TARGET) - needed to fix an issue where clang is not exporting typinfo for classes on Windows
	$(Q)echo >.tmp$$$$ $(OBJS) $(EXTRA_OBJS) && $(DLLTOOL) --export-all-symbols --kill-at -z all$$$$.def @.tmp$$$$ && grep -E '( *_ZTI)|( *_ZThn)|EXPORTS' all$$$$.def | sed 's/ @.*//' >$(DEFFILE) && rm .tmp$$$$ all$$$$.def

$O/$(TARGET): $(DEFFILE)

  endif
endif

#
# TCP implementaion using the Network Simulation Cradle (TCP_NSC feature)
#
# WITH_TCP_NSC := $(shell (cd .. && $(FEATURETOOL) -q isenabled TCP_NSC && echo enabled) )
# ifeq ($(WITH_TCP_NSC), enabled)
#   NSC_VERSION= $(shell ls -d ../3rdparty/nsc* 2>/dev/null | sed 's/^.*-//')
#   ifneq ($(NSC_VERSION),)
#     INCLUDE_PATH += -I../3rdparty/nsc-$(NSC_VERSION)/sim
#     LIBS += -Wl,-rpath,$(abspath ../3rdparty/nsc-$(NSC_VERSION))
#   else
#     $(error Please install NSC or disable 'TCP_NSC' feature)
#   endif
# endif

#
# TCP implementation using the lwIP stack
#
# WITH_TCP_LWIP := $(shell (cd .. && $(FEATURETOOL) -q isenabled TCP_lwIP && echo enabled) )
# ifeq ($(WITH_TCP_LWIP), enabled)
#   INCLUDE_PATH += -Iinet/transportlayer/tcp_lwip/lwip/include -Iinet/transportlayer/tcp_lwip/lwip/include/ipv4 -Iinet/transportlayer/tcp_lwip/lwip/include/ipv6
# endif

#
# pkg-config:
#
HAVE_PKGCFG := $(shell pkg-config --version 2>/dev/null)
ifeq ($(strip $(HAVE_PKGCFG)),)
  HAVE_PKGCFG := no
else
  HAVE_PKGCFG := yes
  PKGCFG := $(shell which pkg-config)
endif

#
# VoipStream feature:
#
# WITH_VOIPSTREAM := $(shell (cd .. && $(FEATURETOOL) -q isenabled VoIPStream && echo enabled) )
# ifeq ($(WITH_VOIPSTREAM), enabled)
#   ifeq ($(HAVE_PKGCFG), yes)
#    HAVE_FFMPEG := $(shell $(PKGCFG) --exists libavcodec libavformat libavutil && echo yes || echo no)
#     ifeq ($(HAVE_FFMPEG), yes)
#       LIBS += $(shell $(PKGCFG) --libs libavcodec libavformat libavutil)
#       CFLAGS += $(shell $(PKGCFG) --cflags libavcodec libavformat libavutil) -DHAVE_FFMPEG
#     endif
#     HAVE_FFMPEG_AVRESAMPLE := $(shell $(PKGCFG) --exists libavresample && echo yes || echo no)
#     ifeq ($(HAVE_FFMPEG_AVRESAMPLE), yes)
#       LIBS += $(shell $(PKGCFG) --libs libavresample)
#       CFLAGS += $(shell $(PKGCFG) --cflags libavresample) -DHAVE_FFMPEG_AVRESAMPLE
#     endif
#   endif
# endif

#
# visualization feature requires (optionally) some extra osg and osgEarth libraries
#
# WITH_VISUALIZERS := $(shell (cd .. && $(FEATURETOOL) -q isenabled visualization && echo enabled) )
# ifeq ($(WITH_VISUALIZERS), enabled)
#   ifeq ($(WITH_OSG), yes)
#     OMNETPP_LIBS += -losg -losgText -losgDB -losgGA -losgViewer -losgUtil -lOpenThreads # TODO: use $(OSG_LIBS) from Makefile.inc? Does that include -losgText? Why not?
#     ifeq ($(WITH_OSGEARTH), yes)
#       OMNETPP_LIBS += -losgEarth -losgEarthUtil # TODO: use $(OSGEARTH_LIBS) from Makefile.inc? -lgeos_c might also be needed. Is that included? Should it be?
#     endif
#   endif
# endif

# uncomment this if you want to run the NS3 vs INET 802.11 cross validation tests in the 'tests/misc/ns3' folder.
# CFLAGS += -DNS3_VALIDATION

# disable anoying "... hides overloaded virtual function" warning
CFLAGS += -Wno-overloaded-virtual

#########################################################################
# precompiled header support for GCC and CLANG

# Set this to "no" if you want to avoid using the precompiled header. The default is "yes".
USE_PRECOMPILED_HEADER ?= yes

# force turning off precompiled headers if ccache is used as it is not compatible with precompiled headers.
ifneq (,$(findstring ccache,$(shell (which $(CC)))))
  USE_PRECOMPILED_HEADER = no
  $(info *** CCACHE detected - precompiled headers disabled)
endif

PRECOMPILED_HEADER=inet/common/precompiled_$(MODE).h

ifeq ($(USE_PRECOMPILED_HEADER),yes)
  ifneq (,$(findstring gcc,$(CC)))
    PRECOMPILED_EXT=gch
  else ifneq (,$(findstring clang,$(CC)))
    PRECOMPILED_EXT=pch
  else
    PRECOMPILED_EXT=
  endif
  CFLAGS += -include $(PRECOMPILED_HEADER)
endif

PRECOMPILED_HEADER_PCH=$(PRECOMPILED_HEADER).$(PRECOMPILED_EXT)
PRECOMPILED_HEADER_D=$(PRECOMPILED_HEADER_PCH:%.$(PRECOMPILED_EXT)=%.d)

# Main target
all-pch: | pch msgheaders all

.PHONY: pch clean-pch

pch : $(PRECOMPILED_HEADER_PCH)

$(PRECOMPILED_HEADER_PCH): $(PRECOMPILED_HEADER)
ifneq ("$(PRECOMPILED_EXT)","")
	@echo Creating precompiled header for $(CC)...
	$(Q)$(CXX) -x c++-header $(CXXFLAGS) $(filter-out -MMD -include $(PRECOMPILED_HEADER),$(COPTS)) -MD -o $@ $<
endif

clean: clean-pch clean-defines

clean-pch:
	$(Q)-rm -f $(PRECOMPILED_HEADER_D) $(PRECOMPILED_HEADER).pch $(PRECOMPILED_HEADER).gch

-include $(PRECOMPILED_HEADER_D)

# Create opp_defines.h so important WITH_* macros from OMNeT++ can be included as macros from a header file
# This helps the IDE to properly enable/disable conditional code in the editor
DEFINES_FILE=inet/opp_defines.h

msgheaders: $(DEFINES_FILE)

clean-defines:
	$(Q)-rm -f $(DEFINES_FILE)

$(DEFINES_FILE) : $(COPTS_FILE)
	@echo "// Generated file, do not edit" >$(DEFINES_FILE)
ifeq ($(WITH_OSG),yes)
	@echo "#ifndef WITH_OSG" >>$(DEFINES_FILE)
	@echo "#define WITH_OSG" >>$(DEFINES_FILE)
	@echo "#endif" >>$(DEFINES_FILE)
endif
ifeq ($(WITH_OSGEARTH),yes)
	@echo "#ifndef WITH_OSGEARTH" >>$(DEFINES_FILE)
	@echo "#define WITH_OSGEARTH" >>$(DEFINES_FILE)
	@echo "#endif" >>$(DEFINES_FILE)
endif

# dump out the actual compiler and linker command line for easier debugging
ifneq ($(MAKECMDGOALS),clean)
$(info *** COMPILING with:)
$(info $(CXX) -c $(CXXFLAGS) $(COPTS))
$(info *** LINKING with:)
$(info $(SHLIB_LD) -o $O/$(TARGET) $(AS_NEEDED_OFF) $(WHOLE_ARCHIVE_ON) $(LIBS) $(WHOLE_ARCHIVE_OFF) $(OMNETPP_LIBS) $(LDFLAGS))
$(info Building...)
endif

# <<<
#------------------------------------------------------------------------------

# Main target
all: $(TARGET_DIR)/$(TARGET)

$(TARGET_DIR)/% :: $O/%
	@mkdir -p $(TARGET_DIR)
	$(Q)$(LN) $< $@
ifeq ($(TOOLCHAIN_NAME),clangc2)
	$(Q)-$(LN) $(<:%.dll=%.lib) $(@:%.dll=%.lib)
endif

$O/$(TARGET): $(OBJS)  $(wildcard $(EXTRA_OBJS)) Makefile $(CONFIGFILE)
	@$(MKPATH) $O
	@echo Creating shared library: $@
	$(Q)$(SHLIB_LD) -o $O/$(TARGET) $(OBJS) $(EXTRA_OBJS) $(AS_NEEDED_OFF) $(WHOLE_ARCHIVE_ON) $(LIBS) $(WHOLE_ARCHIVE_OFF) $(OMNETPP_LIBS) $(LDFLAGS)
	$(Q)$(SHLIB_POSTPROCESS) $O/$(TARGET)

.PHONY: all clean cleanall depend msgheaders smheaders

.SUFFIXES: .cc

$O/%.o: %.cc $(COPTS_FILE) | msgheaders smheaders
	@$(MKPATH) $(dir $@)
	$(qecho) "$<"
	$(Q)$(CXX) -c $(CXXFLAGS) $(COPTS) -o $@ $<

%_m.cc %_m.h: %.msg
	$(qecho) MSGC: $<
	$(Q)$(MSGC) -s _m.cc -MD -MP -MF $O/$(basename $<)_m.h.d $(MSGCOPTS) $?

%_sm.cc %_sm.h: %.sm
	$(qecho) SMC: $<
	$(Q)$(SMC) -c++ -suffix cc $(SMCOPTS) $?

msgheaders: $(MSGFILES:.msg=_m.h)

smheaders: $(SMFILES:.sm=_sm.h)

clean:
	$(qecho) Cleaning $(TARGET)
	$(Q)-rm -rf $O
	$(Q)-rm -f $(TARGET_DIR)/$(TARGET)
	$(Q)-rm -f $(TARGET_DIR)/$(TARGET:%.dll=%.lib)
	$(Q)-rm -f $(call opp_rwildcard, . , *_m.cc *_m.h *_sm.cc *_sm.h)

cleanall:
	$(Q)$(MAKE) -s clean MODE=release
	$(Q)$(MAKE) -s clean MODE=debug
	$(Q)-rm -rf $(PROJECT_OUTPUT_DIR)

# include all dependencies
-include $(OBJS:%=%.d) $(MSGFILES:%.msg=$O/%_m.h.d)
